/**
 * @author LKQ
 * @date 2021/12/24 21:37
 * @description 循环
 */
public class Solution1 {
    public static void main(String[] args) {
        Solution1 solution1 = new Solution1();
        System.out.println(solution1.addDigits(38));
    }
    public int addDigits(int num) {
        if (num < 10) {
            return num;
        }
        int ans = 0;
        while (num >= 10) {
            ans = 0;
            while ( num != 0) {
                int temp = num % 10;
                ans += temp;
                num /= 10;
            }
            num = ans;
        }
        return ans;
    }
}
